<template>
  <div class="page-home">
    <component :is="currentRole" />
    <div class="el-card" style="padding:10px; margin-top:10px;">
      <span>运营数据指标：</span>
      <div><p>页面浏览量： {{ countNum }}</p></div>
      <!-- <div><p>政务信息浏览量： {{ typeOneNum }}</p></div>
      <div><p>文化信息浏览量： {{ typeTwoNum }}</p></div>
      <div><p>新闻资讯浏览量： {{ typeThreeNum }}</p></div>
      <div><p>志愿者信息浏览量：{{ typeFourNum }}</p></div> -->
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import AdminHome from './components/admin'
import OtherHome from './components/other'

export default {
  name: 'HomeCenter',
  components: { AdminHome, OtherHome },
  data() {
    return {
      currentRole: 'AdminHome',
      countNum: '',
      typeFourNum: '',
      typeOneNum: '',
      typeThreeNum: '',
      typeTwoNum: ''
    }
  },
  computed: {
    ...mapGetters([
      'authRules'
    ])
  },
  created() {
    if (!this.authRules.includes('admin')) {
      this.currentRole = 'OtherHome'
    }
  },
  mounted() {
    this.InitStatistics()
  },
  methods: {
    InitStatistics() {
      const params = {}
      this.$http
        .get('statistics/number', params)
        .then(response => {
          this.countNum = response.countNum
          this.typeFourNum = response.typeFourNum
          this.typeOneNum = response.typeOneNum
          this.typeThreeNum = response.typeThreeNum
          this.typeTwoNum = response.typeTwoNum
        })
        .catch(response => {
          this.$error(response)
        })
    }
  }
}
</script>
